package com.iflytek.aisol.audit.iflytek.strategy.manage.controller;

import com.iflytek.aisol.audit.iflytek.strategy.manage.dto.ServerInstanceDTO;
import com.iflytek.aisol.audit.iflytek.strategy.manage.entity.ServerInstance;
import com.iflytek.aisol.audit.iflytek.strategy.manage.query.PageDTO;
import com.iflytek.aisol.audit.iflytek.strategy.manage.common.entity.R;
import com.iflytek.aisol.audit.iflytek.strategy.manage.query.ServicePageQuery;
import com.iflytek.aisol.audit.iflytek.strategy.manage.query.ServiceVO;
import com.iflytek.aisol.audit.iflytek.strategy.manage.service.ServiceConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * CLassName: ServiceConfigController
 * Description:
 * Author: wuzhixiang
 * Date: 2024-12-28 16:06
 * Version: 1.0
 */
@RestController
@RequestMapping("/service-config")
@Slf4j
@Api(tags = "服务配置管理")
public class ServiceConfigController {

    @Autowired
    private ServiceConfigService serviceConfigService;

    /**
     * 新增服务配置接口
     */
    @PostMapping
    @ApiOperation(value = "server 新增配置")
    public R<?> add(@RequestBody ServerInstanceDTO serverInstanceDTO){
        log.info("插入的数据为：{}", serverInstanceDTO);
        serviceConfigService.add(serverInstanceDTO);
        return R.success();
    }

    /**
     * 修改服务配置接口
     * @param id 根据id修改
     * @param serverInstanceDTO 前端传入的
     * @return
     */
    @PutMapping("/{id}")
    @ApiOperation(value = "server 修改配置")
    public R<?> update(@PathVariable Long id, @RequestBody ServerInstanceDTO serverInstanceDTO){
        serviceConfigService.update(id,serverInstanceDTO);
        return R.success();
    }

    /**
     * 删除服务配置接口
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "server 删除配置")
    public R<?> delete(@PathVariable Long id){
        serviceConfigService.delete(id);
        return R.success();
    }

    /**
     * 分页查询
     * @param query
     * @return
     */
    @GetMapping("/page")
    @ApiOperation(value = "server 分页查询")
    public R<PageDTO<ServerInstance>> queryServicePage(ServicePageQuery query) {
        log.info("分页查询：{}",query);
        PageDTO<ServerInstance> result = serviceConfigService.queryServicePage(query);
        return R.success(result);
    }

}
